import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Z.YD
 * Date: 2025-07-28
 * Time: 21:57
 */
public class Mystack1 {
    public int[] elem;
    public int usedSize;

    public Mystack1() {
        this.elem = new int[10];
    }

    public boolean isFull() {
        return usedSize == elem.length;
    }

    public void push(int val) {
        if(isFull()) {
            this.elem = Arrays.copyOf(elem,2*elem.length);
        }
        elem[usedSize++] = val;
    }

    public int pop() {
       if(isEmpty()) {
           throw new RuntimeException();
       }
       int val = elem[usedSize-1];
       usedSize--;
       return val;
    }

    public int peek() {
        if(isEmpty()) {
            throw new RuntimeException();
        }
        return elem[usedSize-1];
    }

    private boolean isEmpty() {
        return 0 == usedSize;
    }
}
